<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class SectionsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|min:4',
            'order' => 'required|numeric',
            'subject' => 'required|numeric',

        ];
    }
    public function messages()
    {
        return [
            'name.required' => '章节名是必填的',
            'name.min'      => '章节名至少4个字符',
            'order.required' => '权重是必填的',
            'order.numeric'   => '权重只能数值',
            'subject.required' => '你想做什么？',
            'subject.numeric'   => '你想做什么？',

        ];
    }
    public function failedValidation(Validator $validator)
    {
        throw (new HttpResponseException(response()->json([
            'message' => $validator->errors()->first(),
        ], 422)));
    }
}
